import request from './requests.js'
import axios from 'axios'
import {
	select_sku_attribute_url
} from "./setting.js"

import {
	Toast
} from 'vant'

import {
	getLocalTime
} from "./date.js"


function joint_attribute(val) {

	if (val.length == 0) {
		return '没有属性,请尽快添加'
	}

	let res = ''

	for (let i = 0; i < val.length; i++) {
		res = res + val[i].attribute_key + ':' + val[i].attribute_value

		if (i != val.length - 1) {
			res = res + ', '
		}
	}

	return res

}



function select_sku_attribute(sku_id, callBack) {


	//获取属性
	request({
		method: 'GET',
		url: select_sku_attribute_url,
		params: {
			sku_id: sku_id
		}
	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let result = response.data.resultBody.reverse()
		// console.log(result)
		//添加属性
		// val['attribute'] = result
		// 添加属性拼接的字符串
		result['attribute_str'] = joint_attribute(result)

		// sku_list.push(val)
		
		callBack(result)



	}).catch((error) => {
		console.log(error) //请求失败返回的数据
		Toast('远程接口问题请联系管理员！！')
	})


}


// async function get_odd_detail(odd_id, callBack){

// 	let res = await get_odd_detail(odd_id)

// 	callBack(res)

// }
export default select_sku_attribute
